package com.itheima;

//懒汉式：不随着类的创建而创建对象，调用getInstance方法先做判断，如果该对象为空，则再创建对象
public class Singleton3 {
    private static Singleton3 singleton3 = null;

    private Singleton3() {

    }

    public static synchronized Singleton3 getInstance() {
        //双重锁，防止多线程中，可能会出现两个对象的情况
        if (singleton3 == null) {
            synchronized (Singleton3.class) {
                if (singleton3 == null) {
                    singleton3 = new Singleton3();
                }
            }
        }
        return singleton3;
    }

    @Override
    public String toString() {
        return "我是双重锁的懒汉式";
    }
}
